package ga.mdm.PolicyManager;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import static android.content.Context.TELEPHONY_SERVICE;

import com.gosuncn.zfyfw.service.GSFWManager;

public class PolicyManager {

    private static final String TAG = PolicyManager.class.getSimpleName();

    private static PolicyManager mPolicyManager;

    private TelephonyManager mTelephonyManager;

    /**
     *
     * @return 获取mPolicyManager实例
     */
    public static PolicyManager getInstance(){
        if(mPolicyManager == null){
            synchronized (PolicyManager.class){
                if(mPolicyManager == null){
                    mPolicyManager = new PolicyManager();
                }
            }
        }
        return mPolicyManager;
    }

    /**
     * get imei
     * @param context
     * @return
     */
    public String getImei(Context context){
        if (ContextCompat.checkSelfPermission(context,
                Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            return null;
        }
        if(mTelephonyManager == null) {
            mTelephonyManager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
        }
        try {
            String imeiStr = mTelephonyManager.getDeviceId();
            return TextUtils.isEmpty(imeiStr) ? null : imeiStr;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 测试依赖关系
     * @param context
     */
    public static void startDialerActivity(Context context) {
        GSFWManager.startDialerActivity(context);
    }
}
